$(".mweb_modal_back_button").click(function(){
    history.go(-1);
});
//定时器------------------------------------------------
var timer;
//点击状态----------------------------------------------
//var isclick="no";
//调整其他金额空间位置----------------------------------
var screenwidth=parseFloat(window.screen.availWidth);
var screenheight=parseFloat(window.screen.availHeight);
$(".table").css({"width":screenwidth-46+"px","marginTop":(screenheight-225)/2+"px"});
//微信数据----------------------------------------------
var timestampone,nonceStrone,signatureone,sign;
var ip=returnCitySN["cip"].toString();//IP
var id=$.cookie("MYID");
//点击选择金额------------------------------------------
var choiceindex=0;//初始按钮
var amount="5";//初始金额
var amount2="0";//初始自定义金额
var moneyhash={
    "m5":5,
    "m10":10,
    "m30":30,
    "m50":50,
    "m100":100,
    "m200":200,
    "m500":500
};
var allmoneychioce=$("div[id^='m']");
console.log(allmoneychioce);
for(var i= 0,len=allmoneychioce.length;i<len;i++){
    allmoneychioce[i].index=i;
    allmoneychioce[i].onclick=function(){
        allmoneychioce[choiceindex].className="";
        allmoneychioce[this.index].className="checked";
        choiceindex=this.index;
        amount=moneyhash[allmoneychioce[this.index].id];
        $("#paybtn span").html(amount);
    }
}
//选择其他金额------------------------------------------
$("#otherchoice").click(function(){
    $("#otherchoiceplace").css("display","block");
    $("#othermoney").val("");
    $("#paybtn2").attr("class","");
    $("#paybtn2 span").html("");
    //$("#othermoney").focus();
});
$("#closeotherchoice").click(function(){
    $("#othermoney").val("");
    $("#paybtn2").attr("class","");
    $("#paybtn2 span").html("");
    $("#otherchoiceplace").css("display","none");
});
$("#othermoney").bind("input","change",function(){
    if($("#othermoney").val().match(/^[1-9]$|^[1-9][0-9]{1,3}$|^[1-9][0-9]{1,3}\.[0-9]{1,2}$|^[1-9]{1,4}\.[0-9]{1,2}$|^0\.[1-9]$|^0\.[0-9][1-9]$/)){
        amount2=$("#othermoney").val();
        $("#paybtn2 span").html(amount2+"元");
        $("#paybtn2").attr("class","checked");
    }else{
        amount2=0;
        $("#paybtn2 span").html("");
        $("#paybtn2").attr("class","");
    }
});
//关闭扫码页面------------------------------------------
$("#closebtn").click(function(){
    $("#QRcode").css("display","none");
    $("#page_wrapper").css("display","block");
    $("#output canvas").remove();
    clearTimeout(timer);
});
//付钱方法----------------------------------------------
var orderid="";//订单号
function payftn(amount){

    $("#wxexplain").css("display","block");//微信扫码提示
    $("#outputbox").css("display","block");//微信支付
    $("#payokinfo").css("display","none");//支付成功信息

    $.ajax({
        type:"get",
        url:"getPrePay.ashx?amount="+amount+"&ip="+ip+"&trade_type=NATIVE&userid="+id,
        datatype:"json",
        success:function(data){
            $("#page_wrapper").css("display","none");
            $("#QRcode").css("display","block");
            $("#output canvas").remove();
            var d=JSON.parse(data);
            console.log(d);
            orderid=d.out_trade_no;
            $("#output").qrcode({
                text:d.code_url,
                height:250,
                width:250,
                src:'img/logo.png'//这里配置Logo的地址即可。
            });
            //二维码生成图片
            var qrCanvas=$("canvas")[0];
            var image = new Image();
            image.src = qrCanvas.toDataURL("image/png");
            $("#output").append(image);

            isclick="yes";
            //修改成功提醒数据--------------------------
            $("#showpaynum").html("¥"+amount);
            $("#orderid").html(orderid);
            //获取扫码支付状态--------------------------
            getcallback(orderid);
        }
    });
}
//点击付款----------------------------------------------
$("#paybtn").click(function(){
    payftn(amount);
});
$("#paybtn2").click(function(){
    if($("#paybtn2").attr("class")==="checked"){
        payftn(amount2);
    }
});
//接收支付完成结果-------------------------------------
function getcallback(orderid){
    $.ajax({
        type:"get",
        datatype:"json",
        url:paystateurl+orderid,
        success:function(d){
            d=JSON.parse(d);
            //console.log(d.msg);
            if(d.msg==="还未支付"){
                timer=setTimeout("getcallback(orderid)",2000);
            }else if(d.msg==="支付成功"){
                clearTimeout(timer);
                $("#output canvas").remove();//清除二维码
                $("#outputbox").css("display","none");//微信扫码提示
                $("#otherchoiceplace").css("display","none");
                $("#payokinfo").css("display","block");//支付成功信息
                console.log("支付成功");
            }
        }
    });

}